package cn.rainshare.service.impl;

import cn.rainshare.dao.StuDao;
import cn.rainshare.entity.Student;
import cn.rainshare.exce.InsertException;
import cn.rainshare.service.StuService;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public class StuServiceImpl implements StuService {

    private StuDao stuDao;

    public void setStuDao(StuDao stuDao) {
        this.stuDao = stuDao;
    }

    @Override
    /*@Transactional(
            propagation = Propagation.REQUIRED,
            isolation = Isolation.DEFAULT,
            readOnly = false,
            rollbackFor = {
                    InsertException.class,
                    NullPointerException.class
            }
    )*/

    public int addStu(Student student) {

        int num = stuDao.insertStu(student);

        if (student.getId() < 1000) {
            throw new InsertException("编号:"+student.getId()+"不允许！");
        }

        return num;

    }

    @Override
    public List<Student> queryAllStu() {

        List<Student> students = stuDao.queryAllStu();
        return students;
    }
}
